package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.DeliveryOrder;
import com.example.demo.entity.PurchaseOrder;
import com.example.demo.service.DeliveryOrderService;
import com.example.demo.mapper.DeliveryOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【delivery_order】的数据库操作Service实现
* @createDate 2025-02-06 13:40:48
*/
@Service
public class DeliveryOrderServiceImpl extends ServiceImpl<DeliveryOrderMapper, DeliveryOrder>
    implements DeliveryOrderService{
    @Autowired
    DeliveryOrderMapper deliveryOrderMapper;
    @Override
    public DeliveryOrder select(String trainingId, String userId,String logisticsNumber,String type) {
        QueryWrapper<DeliveryOrder> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(logisticsNumber!=null){
            queryWrapper.eq("logisticsNumber",logisticsNumber);
        }
        if(type!=null){
            queryWrapper.eq("type",type);
        }
        queryWrapper.orderByDesc("id");
        List<DeliveryOrder> resultList = deliveryOrderMapper.selectList(queryWrapper);
        if (!resultList.isEmpty()) {
            return resultList.get(0); // 这里返回结果列表的第一条记录
        } else {
            return null;
        }
    }

    @Override
    public Integer delete(String userId, String trainingId, String logisticsNumber) {
        QueryWrapper<DeliveryOrder> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }
        if(logisticsNumber!=null){
            queryWrapper.eq("logisticsNumber",logisticsNumber);
        }
        queryWrapper.orderByDesc("id");
        return deliveryOrderMapper.delete(queryWrapper);
    }
}




